package sv.gob.mtps.hr.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import sv.gob.mtps.hr.model.CatTituloAcademico;
import sv.gob.mtps.hr.model.NivTituloVw;

@Repository
public class TituloAcademicoDAOImpl implements TituloAcademicoDAO {
	
	@Autowired
    private SessionFactory sessionFactory;

	@Override
	public void addTituloAcademico(CatTituloAcademico tituloAcademico) {
		this.sessionFactory.getCurrentSession().save(tituloAcademico);

	}

	@Override
	public void updateTituloAcademico(CatTituloAcademico tituloAcademico) {
		this.sessionFactory.getCurrentSession().update(tituloAcademico);

	}

	@Override
	public List<CatTituloAcademico> listTituloAcademico() {
		// TODO Auto-generated method stub
		return this.sessionFactory.getCurrentSession().createQuery("from CatTituloAcademico").list();
	}

	@Override
	public void removeTituloAcademico(Integer id) {
		CatTituloAcademico tituloAcademico = (CatTituloAcademico)this.sessionFactory.getCurrentSession().load(CatTituloAcademico.class, id);
		if(tituloAcademico != null){
			this.sessionFactory.getCurrentSession().delete(tituloAcademico);
		}

	}

	@Override
	public List<NivTituloVw> listTituloAcademico(Integer id) {
		
		return this.sessionFactory.getCurrentSession().createQuery("from NivTituloVw where id.idNivelAcademico="+id).list();
	}

}
